<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Comment;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class CommentController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Comment(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('context');
            $grid->column('user_name');
            $grid->column('user_heard');
            $grid->column('create_time');
            $grid->column('post_id');
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
            // 也可以通过以下方式启用或禁用按钮
            $grid->disableDeleteButton();
            $grid->disableEditButton();
            $grid->disableQuickEditButton();
            $grid->disableViewButton();
            $grid->disableCreateButton();
            $grid->setActionClass(Grid\Displayers\Actions::class);
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Comment(), function (Show $show) {
            $show->field('id');
            $show->field('context');
            $show->field('user_name');
            $show->field('user_heard');
            $show->field('create_time');
            $show->field('post_id');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Comment(), function (Form $form) {
            $form->display('id');
            $form->text('context');
            $form->text('user_name');
            $form->text('user_heard');
            $form->text('create_time');
            $form->text('post_id');
        });
    }
}
